/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Pesan;

/**
 *
 * @author tashiba
 */
public class PesanTableModel extends AbstractTableModel {

    private List<Pesan> pes = new ArrayList<Pesan>();

    public PesanTableModel(List<Pesan> pesanan) {
        this.pes = pesanan;
    }

    public void deletePesanan(int row) {
        pes.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updatePesanan(int row, Pesan pesanan) {
        pes.set(row, pesanan);
        fireTableRowsUpdated(row, row);
    }

    public void addPesanan(Pesan pesanan) {
        pes.add(pesanan);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    @Override
    public int getRowCount() {
        return pes.size();
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Pesan b = pes.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getIdPesanan();
            case 1:
                return b.getWaktuPesan();
            case 2:
                return b.getPembeli().getNoMeja();
            case 3:
                return b.getMenu().getNamaMenu();
            case 4:
                return b.getJumlahPesanan();
            case 5:
                return b.getStatus();
            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Id Pesan";
            case 1:
                return "Waktu Pesan";
            case 2:
                return "Nomor Meja";
            case 3:
                return "Nama Menu";
            case 4:
                return "Jumlah Pesanan";
            case 5:
                return "Status";
            default:
                return "";
        }
    }
}
